package znbkTopicType.resContent;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.TextView;

import com.example.lancooznbk.R;
import com.example.lancooznbk.view.widget.VoicePlayer;

import znbkTopicType.WrapBaseAdapter;
import znbkTestPaperInfor.ZnbkPaperDef;

import static znbkTestPaperBj.activity.NotePaperActivity.mEntityBj;
import static znbkTestPaperRdtz.activity.HeatPointExtensionPaperActivity.mEntityRdtz;
import static znbkTestPaperSc.activity.CollectionPaperActivity.mEntitySc;

/**
 * Created by Administrator on 2018\3\18 0018.
 */

public class ZnbkContentResStlTlAdapter extends WrapBaseAdapter {

    private LayoutInflater mInflater;
    private Context mContext;
    //当前试题数量
    private int SumItem;
    //当前试题在当前试卷的ID
    private int PaperID;
    private int ModelFrom;//试卷来源


    private ViewHolder holder = null;
    private class ViewHolder{
        TextView mTvArticle;
        ImageButton BtnPlayPause;
        TextView TvAnswerTime;
        SeekBar SbMusic;

        private ViewHolder(View convertView) {
            mTvArticle = (TextView) convertView.findViewById(R.id.tv_Artitle);
            BtnPlayPause = (ImageButton) convertView.findViewById(R.id.btn_start);
            TvAnswerTime = (TextView) convertView.findViewById(R.id.tv_answerTime);
            SbMusic = (SeekBar) convertView.findViewById(R.id.music_progress);
        }
    }

    /*
   * 获取小题选项信息
   * */
    public ZnbkContentResStlTlAdapter(Context context, int sumItem, int paperID, int modelFrom) {
        mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.SumItem = sumItem;
        this.PaperID = paperID;
        this.ModelFrom = modelFrom;
    }

    @Override
    public int getCount() {
        return SumItem;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.znbk_adapter_content_stl_tl_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        /*
        * 获取作文题用户相关信息
        * */
        getQuesInfor();

        /*
        * 显示题干信息
        * */
        showQuesInfor();


        return convertView;
    }


    /*
    * 获取作文题用户相关信息
    * */
    private String AudioPath = "";
    private String Artitle = "";
    private void  getQuesInfor(){

        if(ModelFrom== ZnbkPaperDef.FROM_HEAT_POINT_EXTENSION){


                /*
                * 音频路径
                * */
                AudioPath = mEntityRdtz.getResFromTK().getAudioList().get(0).getAudioPath();

                /*
                * 文本内容
                * */
                Artitle = "<font color='#47D05A'><middle><middle>" + "(听力原文)" + "</middle></middle></font>" +
                        mEntityRdtz.getResFromTK().getAudioList().get(0).getArticle();

        }else if(ModelFrom==ZnbkPaperDef.FROM_COLLECTION){


                /*
                * 音频路径
                * */
                AudioPath = mEntitySc.getResDetail().getAudioList().get(0).getAudioPath();

                /*
                * 文本内容
                * */
                Artitle = "<font color='#47D05A'><middle><middle>" + "(听力原文)" + "</middle></middle></font>" +
                        mEntitySc.getResDetail().getAudioList().get(0).getArticle();

        }else if(ModelFrom==ZnbkPaperDef.FROM_NOTE){


                /*
                * 音频路径
                * */
            AudioPath = mEntityBj.getModelTKQue().getAudioList().get(0).getAudioPath();

                /*
                * 文本内容
                * */
            Artitle = "<font color='#47D05A'><middle><middle>" + "(听力原文)" + "</middle></middle></font>" +
                    mEntityBj.getModelTKQue().getAudioList().get(0).getArticle();

        }

    }

    /*
    * 显示界面信息
    * */
    private void showQuesInfor(){
        mVoicePlayer = new VoicePlayer(holder.SbMusic,AudioPath,holder.TvAnswerTime,holder.BtnPlayPause,true);
        holder.mTvArticle.setText(Html.fromHtml(Artitle));
    }

}